home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / UNGETC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  637 b   |  18 lines

  1. /* ungetc.c --- p 472 */
  2. #include <stdio.h>
  3. #include <ctype.h>                /* For the macro isdigit() */
  4. main()
  5. {
  6.     int intval = 0, c;
  7.     char buff[81];
  8.                     /* Ask user to type in an integer */
  9.     printf("Enter an integer followed by some other characters:");
  10.     while ( (c = getchar()) != EOF && isdigit(c) )
  11.         intval = 10*intval + c - 48;         /* 0 is ASCII 48 */
  12.             /* Push back the first non-digit read from stdin */
  13.     if (c != EOF) ungetc(c, stdin);
  14.                         /* Print message to user */
  15.     printf("Integer you entered = %d.\n Rest of the string beginning "
  16.         "at the first non-integer in buffer: %s\n",
  17.                             intval, gets(buff));
  18. }